<template>
  <div>
    <city-header></city-header>
    <city-search :cities="cities"></city-search>
    <city-list :hotCities="hotCities" :cities="cities" :letter="letter"
    >
    </city-list>
    <alphabet :cities="cities" @letterChange="handleLetterChange"></alphabet>
  </div>
</template>
<script>
import CityHeader from './components/CityHeader.vue'
import CitySearch from './components/CitySearch.vue'
import CityList from './components/CityList.vue'
import Alphabet from './components/Alphabet.vue'
import axios from 'axios'
export default {
  name: 'City',
  components: {
    CityHeader,
    CitySearch,
    CityList,
    Alphabet
  },
  data () {
    return {
      cityData: {},
      hotCities: [],
      cities: {},
      letter: ''
    }
  },
  methods: {
    getCityInfo () {
      axios.get('/static/mock/city.json')
        .then((response) => {
          const cityInfo = response.data
          if (cityInfo.ret && cityInfo.data) {
            this.cityData = cityInfo.data
            this.hotCities = this.cityData.hotCities
            this.cities = this.cityData.cities
          }
        })
        .catch((error) => {
          console.log(error)
        })
    },
    handleLetterChange (letter) {
      this.letter = letter
    }
  },
  mounted () {
    this.getCityInfo()
  }
}
</script>
<style lang="stylus" scoped>
</style>
